package 乘方;

public class Solution1
{
   public double Power1(double base,int exponent)
   {
       if(exponent==0)
           return 1;
       if (exponent==1)
           return base;
       double result=Power1(base,exponent>>1);
       result*=result;
       if ((exponent&1)==1)
           result*=base;
       return result;
   }
    public double Power(double base, int exponent)
    {
        //分类，正数，负数和0
        double result=1.0;
        if (exponent==0)
            return 1.0;
        if (base==0)
            return 0.0;
        int absexponent=Math.abs(exponent);
        result= Power1(base,absexponent);
        if (exponent<0)
            result=1.0/result;
        return result;
    }

    public static void main(String[] args)
    {

        Solution1 solution = new Solution1();
        System.out.println(solution.Power(2,7));
    }
}
